package cn.itcast.java.thread;

/**
 * Author itcast
 * Date 2021/10/14 16:24
 * 开发步骤：
 * 1.创建类继承 Thread类并重写run方法
 * 2.调用子类
 */
public class ThreadDemo01 {
    public static void main(String[] args) {
        System.out.println("main线程中开始执行");
        //实现一个单线程，打印输出 1 ~ 100 之间数字
        MyThread thread = new MyThread("打印数字线程");
        thread.setPriority(10);
        thread.start();
        //主线程中打印 100 ~ 0
        Thread.currentThread().setPriority(1);
        for (int i = 100; i > 0; i--) {
            System.out.println(Thread.currentThread().getName() + ":" + i);
        }
    }

    public static class MyThread extends Thread {
        public MyThread(String name) {
            super(name);
        }

        @Override
        public void run() {
            for (int i = 0; i < 100; i++) {
                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + ":" + i);
            }
        }
    }
}
